<?php
/**
 * PHP Framework SEO meta tags builder class
 * @author Max Kazakov <kazakov.max@gmail.com>
 * @author Andrew <andrew@vitche.com>
 * @author Frozen Rain <frozenrain@mail.ru>
 **/
class MetaTagsBuilder {

    private static $_metaTitle = array();

    private static $_metaKeywords = array();

    private static $_metaDescription = array();

    private static $_metaCopyright = array();

    private static $_titleSeparator = " ";

    private static $_keywordsSeparator = ",";

    private static $_descriptionSeparator = " ";

    public static function clearAll($clearAll = false) {
        self::$_metaTitle       = array();
        self::$_metaCopyright   = array();
        self::$_metaDescription = array();
        self::$_metaKeywords    = array();
    }

    public static function clear($key = null) {

        if ($key == null) {
            return self::clearAll();
        }

        self::${"_meta" . $key} = array();
    }

    public static function assign($key, $value) {
        self::${"_meta" . $key}[] = $value;
    }

    public static function render() {
        $title = implode(self::$_titleSeparator, self::$_metaTitle);
        $keywords = implode(self::$_keywordsSeparator, self::$_metaKeywords);
        $description = implode(self::$_descriptionSeparator, self::$_metaDescription);
        return "<title>$title</title>\r\n"
            . "<meta name=\"keywords\" content=\"$keywords\" />\r\n"
            . "<meta name=\"description\" content=\"$description\" />\r\n"
            . "<meta name=\"copyright\" content=\"" . implode(" ", self::$_metaCopyright) . "\" />\r\n";
    }
}
?>